package com.paygate.controller

import com.paygate.entity.req.PayReq
import com.paygate.entity.req.PayResultReq
import com.paygate.service.PayService
import org.springframework.stereotype.Controller
import org.springframework.ui.Model
import org.springframework.validation.annotation.Validated
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestMapping

@Controller
@RequestMapping("/pay")
open class PayController(private val payService: PayService) {

    @PostMapping("")
    fun pay(@Validated req:PayReq, model:Model): String {
        model.addAllAttributes(payService.pay(req))
        return "checkout";
    }

    @PostMapping("/result")
    fun result(@Validated req: PayResultReq, model:Model): String {
        val map = payService.handleResult(req)
        model.addAllAttributes(map)
        return "result";
    }
}